<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>MySQL建库建表 | Introduction</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/part1/4.DML操作：增,删,改.html" />
    
    
    <link rel="prev" href="../../home/part1/2.MySQL数据类型.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.3"
        data-chapter-title="MySQL建库建表"
        data-filepath="home/part1/3.MySQL建库建表.md"
        data-basepath="../.."
        data-revision="Sun Oct 21 2018 16:32:53 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="home/MySQL介绍.html">
            
                
                    <a href="../../home/MySQL介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        MySQL介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="home/part1/MySQL基础.html">
            
                
                    <a href="../../home/part1/MySQL基础.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Mysql基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/part1/1.MySQL基础操作.html">
            
                
                    <a href="../../home/part1/1.MySQL基础操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        MySQL基础操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/part1/2.MySQL数据类型.html">
            
                
                    <a href="../../home/part1/2.MySQL数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        MySQL数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.3" data-path="home/part1/3.MySQL建库建表.html">
            
                
                    <a href="../../home/part1/3.MySQL建库建表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        MySQL建库建表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="home/part1/4.DML操作：增,删,改.html">
            
                
                    <a href="../../home/part1/4.DML操作：增,删,改.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        DML操作：增,删,改
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="home/part1/5.DQL操作：数据查询.html">
            
                
                    <a href="../../home/part1/5.DQL操作：数据查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        DQL操作：数据查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="home/part1/6.数据导入和导出.html">
            
                
                    <a href="../../home/part1/6.数据导入和导出.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        数据导入和导出
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="home/part2/MySQL高级.html">
            
                
                    <a href="../../home/part2/MySQL高级.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        MySQL高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/part2/1.MySQL的多表联查.html">
            
                
                    <a href="../../home/part2/1.MySQL的多表联查.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        MySQL的多表联查
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/part2/2.MySQL的事务处理.html">
            
                
                    <a href="../../home/part2/2.MySQL的事务处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        MySQL的事务处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/part2/3.MySQL的视图及其它.html">
            
                
                    <a href="../../home/part2/3.MySQL的视图及其它.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        MySQL的视图及其它
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/part2/4.MySQL的触发器.html">
            
                
                    <a href="../../home/part2/4.MySQL的触发器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        MySQL的触发器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="home/part2/6.MySQL日志及数据恢复.html">
            
                
                    <a href="../../home/part2/6.MySQL日志及数据恢复.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        MySQL日志及数据恢复
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="home/part2/7.慢查询及sql优化.html">
            
                
                    <a href="../../home/part2/7.慢查询及sql优化.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        慢查询及sql优化
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="home/part3/Python连接MySQL.html">
            
                
                    <a href="../../home/part3/Python连接MySQL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Python连接MySQL
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/part3/1.CRUD.html">
            
                
                    <a href="../../home/part3/1.CRUD.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        CRUD
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Introduction</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="mysql-&#x6570;&#x636E;&#x5E93;">MySQL &#x6570;&#x636E;&#x5E93;</h1>
<hr>
<ul>
<li><h3 id="&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;">&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;</h3>
<pre><code class="lang-sql">  &#x4F7F;&#x7528;root&#x767B;&#x5F55;&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;

  <span class="hljs-operator"><span class="hljs-keyword">create</span> <span class="hljs-keyword">database</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">exists</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">charset</span> utf8
</span></code></pre>
<ul>
<li><p>&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x8BE5;&#x547D;&#x4EE4;&#x7684;&#x4F5C;&#x7528;&#xFF1A;</p>
<ul>
<li>&#x5982;&#x679C;&#x6570;&#x636E;&#x5E93;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x521B;&#x5EFA;&#xFF0C;&#x5B58;&#x5728;&#x5219;&#x4E0D;&#x521B;&#x5EFA;&#x3002;</li>
<li>&#x521B;&#x5EFA;RUNOOB&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5E76;&#x8BBE;&#x5B9A;&#x7F16;&#x7801;&#x96C6;&#x4E3A;utf8</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li><h3 id="&#x5220;&#x9664;&#x6570;&#x636E;&#x5E93;">&#x5220;&#x9664;&#x6570;&#x636E;&#x5E93;</h3>
<pre><code class="lang-sql">  &#x5220;&#x5E93;&#x6709;&#x98CE;&#x9669;,&#x52A8;&#x624B;&#x9700;&#x8C28;&#x614E;

  <span class="hljs-operator"><span class="hljs-keyword">drop</span> <span class="hljs-keyword">database</span> py;</span>
</code></pre>
</li>
</ul>
<hr>
<h1 id="mysql-&#x6570;&#x636E;&#x8868;">MySQL &#x6570;&#x636E;&#x8868;</h1>
<ul>
<li><h3 id="&#x521B;&#x5EFA;mysql&#x6570;&#x636E;&#x8868;&#x9700;&#x8981;&#x4EE5;&#x4E0B;&#x4FE1;&#x606F;">&#x521B;&#x5EFA;MySQL&#x6570;&#x636E;&#x8868;&#x9700;&#x8981;&#x4EE5;&#x4E0B;&#x4FE1;&#x606F;</h3>
<ul>
<li>&#x8868;&#x540D;</li>
<li>&#x8868;&#x5B57;&#x6BB5;&#x540D;</li>
<li>&#x5B9A;&#x4E49;&#x6BCF;&#x4E2A;&#x8868;&#x5B57;&#x6BB5;<pre><code class="lang-sql">  <span class="hljs-operator"><span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> &#x8868;&#x540D;(
      &#x5B57;&#x6BB5;&#x540D; &#x7C7B;&#x578B; [&#x5B57;&#x6BB5;&#x7EA6;&#x675F;],
      &#x5B57;&#x6BB5;&#x540D; &#x7C7B;&#x578B; [&#x5B57;&#x6BB5;&#x7EA6;&#x675F;],
      &#x5B57;&#x6BB5;&#x540D; &#x7C7B;&#x578B; [&#x5B57;&#x6BB5;&#x7EA6;&#x675F;]
      ...
  );</span>
</code></pre>
</li>
</ul>
</li>
<li><h3 id="&#x521B;&#x5EFA;&#x8868;">&#x521B;&#x5EFA;&#x8868;</h3>
<ul>
<li><p>&#x901A;&#x8FC7; mysql&gt; &#x547D;&#x4EE4;&#x7A97;&#x53E3;&#x53EF;&#x4EE5;&#x5F88;&#x7B80;&#x5355;&#x7684;&#x521B;&#x5EFA;MySQL&#x6570;&#x636E;&#x8868;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; SQL &#x8BED;&#x53E5;CREATE TABLE&#x6765;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x8868;&#x3002;</p>
</li>
<li><h4 id="&#x5B9E;&#x4F8B;">&#x5B9E;&#x4F8B;</h4>
<pre><code class="lang-sql">  &#x4EE5;&#x4E0B;&#x4E3A;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x8868; runoob_tbl &#x5B9E;&#x4F8B;:

  <span class="hljs-operator"><span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span>(
      <span class="hljs-keyword">id</span> <span class="hljs-built_in">int</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span> AUTO_INCREMENT PRIMARY <span class="hljs-keyword">KEY</span>,
      username <span class="hljs-built_in">varchar</span>(<span class="hljs-number">30</span>) <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span>,
      <span class="hljs-keyword">password</span> <span class="hljs-built_in">char</span>(<span class="hljs-number">32</span>) <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span>,
      email <span class="hljs-built_in">varchar</span>(<span class="hljs-number">100</span>) <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span>,
      pic <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-keyword">default</span> <span class="hljs-string">&apos;./public/img/pic.jpg&apos;</span>
  )<span class="hljs-keyword">engine</span>=<span class="hljs-keyword">innodb</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">charset</span>=utf8;</span>
</code></pre>
</li>
<li><p>&#x5B9E;&#x4F8B;&#x89E3;&#x6790;&#xFF1A;</p>
<pre><code class="lang-sql">  &#x5982;&#x679C;&#x4F60;&#x4E0D;&#x60F3;&#x5B57;&#x6BB5;&#x4E3A; NULL &#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5B57;&#x6BB5;&#x7684;&#x5C5E;&#x6027;&#x4E3A; NOT NULL&#xFF0C; &#x5728;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#x65F6;&#x5982;&#x679C;&#x8F93;&#x5165;&#x8BE5;&#x5B57;&#x6BB5;&#x7684;&#x6570;&#x636E;&#x4E3A;NULL &#xFF0C;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;

  AUTO_INCREMENT&#x5B9A;&#x4E49;&#x5217;&#x4E3A;&#x81EA;&#x589E;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4E00;&#x822C;&#x7528;&#x4E8E;&#x4E3B;&#x952E;&#xFF0C;&#x6570;&#x503C;&#x4F1A;&#x81EA;&#x52A8;&#x52A0;1&#x3002;

  PRIMARY KEY&#x5173;&#x952E;&#x5B57;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x5217;&#x4E3A;&#x4E3B;&#x952E;&#x3002; &#x60A8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x591A;&#x5217;&#x6765;&#x5B9A;&#x4E49;&#x4E3B;&#x952E;&#xFF0C;&#x5217;&#x95F4;&#x4EE5;&#x9017;&#x53F7;&#x5206;&#x9694;&#x3002;

  ENGINE &#x8BBE;&#x7F6E;&#x5B58;&#x50A8;&#x5F15;&#x64CE;&#xFF0C;CHARSET &#x8BBE;&#x7F6E;&#x7F16;&#x7801;&#x3002;
</code></pre>
</li>
<li><p>&#x67E5;&#x770B;&#x8868;&#x7ED3;&#x6784; <strong><code>desc stu</code></strong>;</p>
</li>
<li><p>&#x67E5;&#x770B;&#x5EFA;&#x8868;&#x8BED;&#x53E5; <strong><code>show create table stu\G</code></strong> --&#x67E5;&#x770B;&#x5EFA;&#x8868;&#x7684;&#x8BED;&#x53E5;</p>
</li>
</ul>
</li>
<li><h3 id="&#x4FEE;&#x6539;&#x8868;&#x7ED3;&#x6784;">&#x4FEE;&#x6539;&#x8868;&#x7ED3;&#x6784;</h3>
<blockquote>
<p>&#x683C;&#x5F0F;&#xFF1A; alter table &#x8868;&#x540D; action&#xFF08;&#x66F4;&#x6539;&#x9009;&#x9879;&#xFF09;;</p>
</blockquote>
<ul>
<li><p>&#x6DFB;&#x52A0;&#x5B57;&#x6BB5;:</p>
<pre><code class="lang-sql">&#x6DFB;&#x52A0;&#x5B57;&#x6BB5;&#xFF1A;<span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> &#x8868;&#x540D; <span class="hljs-keyword">add</span> &#x5B57;&#x6BB5;&#x540D;&#x4FE1;&#x606F;
&#x4F8B;&#x5982;&#xFF1A;

<span class="hljs-comment">-- &#x5728;user&#x8868;&#x7684;&#x6700;&#x540E;&#x8FFD;&#x52A0;&#x4E00;&#x4E2A;num&#x5B57;&#x6BB5; &#x8BBE;&#x7F6E;&#x4E3A;int not null</span>

<span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">add</span> <span class="hljs-keyword">num</span> <span class="hljs-built_in">int</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span>;</span>

<span class="hljs-comment">-- &#x5728;user&#x8868;&#x7684;email&#x5B57;&#x6BB5;&#x540E;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;age&#x5B57;&#x6BB5;&#xFF0C;&#x8BBE;&#x7F6E;int not null default 20&#xFF1B;</span>

<span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">add</span> age <span class="hljs-built_in">int</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">default</span> <span class="hljs-number">20</span> <span class="hljs-keyword">after</span> email;</span>

<span class="hljs-comment">-- &#x5728;user&#x8868;&#x7684;&#x6700;&#x524D;&#x9762;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;aa&#x5B57;&#x6BB5;&#x8BBE;&#x7F6E;&#x4E3A;int&#x7C7B;&#x578B;</span>

<span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">add</span> aa <span class="hljs-built_in">int</span> <span class="hljs-keyword">first</span>;</span>
</code></pre>
</li>
<li><p>&#x5220;&#x9664;&#x5B57;&#x6BB5;:</p>
<pre><code class="lang-sql">  &#x5220;&#x9664;&#x5B57;&#x6BB5;&#xFF1A;<span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> &#x8868;&#x540D; <span class="hljs-keyword">drop</span> &#x88AB;&#x5220;&#x9664;&#x7684;&#x5B57;&#x6BB5;&#x540D;

  &#x4F8B;&#x5982;&#xFF1A;<span class="hljs-comment">-- &#x5220;&#x9664;user&#x8868;&#x7684;aa&#x5B57;&#x6BB5;</span>

  <span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">drop</span> aa;</span>
</code></pre>
</li>
<li><p>&#x4FEE;&#x6539;&#x5B57;&#x6BB5;:</p>
<pre><code class="lang-sql">  &#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#xFF1A;<span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> &#x8868;&#x540D; <span class="hljs-keyword">change</span>\[<span class="hljs-keyword">modify</span>\] &#x88AB;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x5B57;&#x6BB5;&#x4FE1;&#x606F;

  &#x5176;&#x4E2D;&#xFF1A;<span class="hljs-keyword">change</span>&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#x540D;&#xFF0C; <span class="hljs-keyword">modify</span> &#x4E0D;&#x4FEE;&#x6539;

  &#x4F8B;&#x5982;&#xFF1A;

  <span class="hljs-comment">-- &#x4FEE;&#x6539;user&#x8868;&#x4E2D;age&#x5B57;&#x6BB5;&#x4FE1;&#x606F;&#xFF08;&#x7C7B;&#x578B;&#xFF09;&#xFF0C;&#xFF08;&#x4F7F;&#x7528;modify&#x5173;&#x952E;&#x5B57;&#x7684;&#x76EE;&#x7684;&#x4E0D;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#x540D;&#xFF09;</span>

  <span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">modify</span> age tinyint <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">default</span> <span class="hljs-number">20</span>;</span>

  <span class="hljs-comment">-- &#x4FEE;&#x6539;user&#x8868;&#x7684;num&#x5B57;&#x6BB5;&#x6539;&#x4E3A;mm&#x5B57;&#x6BB5;&#x5E76;&#x6DFB;&#x52A0;&#x4E86;&#x9ED8;&#x8BA4;&#x503C;&#xFF08;&#x4F7F;&#x7528;change&#x53EF;&#x4EE5;&#x6539;&#x5B57;&#x6BB5;&#x540D;&#xFF09;</span>

  <span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">change</span> <span class="hljs-keyword">num</span> mm <span class="hljs-built_in">int</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">default</span> <span class="hljs-number">10</span>;</span>
</code></pre>
</li>
<li><p>&#x6DFB;&#x52A0;&#x548C;&#x5220;&#x9664;&#x7D22;&#x5F15;:</p>
<pre><code class="lang-sql">  &#x6DFB;&#x52A0;&#x548C;&#x5220;&#x9664;&#x7D22;&#x5F15;

  <span class="hljs-comment">-- &#x4E3A;user&#x8868;&#x4E2D;&#x7684;name&#x5B57;&#x6BB5;&#x6DFB;&#x52A0;&#x552F;&#x4E00;&#x6027;&#x7D22;&#x5F15;&#xFF0C;&#x7D22;&#x5F15;&#x540D;&#x4E3A;uni_name;</span>
  <span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">add</span> <span class="hljs-keyword">unique</span> uni_name(<span class="hljs-keyword">name</span>);</span>

  <span class="hljs-comment">-- &#x4E3A;user&#x8868;&#x4E2D;&#x7684;email&#x5B57;&#x6BB5;&#x6DFB;&#x52A0;&#x666E;&#x901A;&#x7D22;&#x5F15;&#xFF0C;&#x7D22;&#x5F15;&#x540D;&#x4E3A;index_eamil</span>

  <span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">add</span> <span class="hljs-keyword">index</span> index_email(email);</span>

  <span class="hljs-comment">-- &#x5C06;user&#x8868;&#x4E2D;index_email&#x7684;&#x7D22;&#x5F15;&#x5220;&#x9664;</span>

  <span class="hljs-operator"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">drop</span> <span class="hljs-keyword">index</span> index_email;</span>
</code></pre>
</li>
<li><p>&#x4FEE;&#x6539;&#x8868;&#x540D;:</p>
<pre><code class="lang-sql">  <span class="hljs-operator"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> &#x65E7;&#x8868;&#x540D; <span class="hljs-keyword">RENAME</span> <span class="hljs-keyword">AS</span> &#x65B0;&#x8868;&#x540D;
</span></code></pre>
</li>
<li><p>&#x66F4;&#x6539;AUTO_INCREMENT&#x521D;&#x59CB;&#x503C;:</p>
<pre><code class="lang-sql">  <span class="hljs-operator"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> &#x8868;&#x540D;&#x79F0; AUTO_INCREMENT=<span class="hljs-number">1</span>
</span></code></pre>
</li>
<li><p>&#x66F4;&#x6539;&#x8868;&#x7C7B;&#x578B;:</p>
<pre><code class="lang-sql">  <span class="hljs-operator"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> &#x8868;&#x540D;&#x79F0; <span class="hljs-keyword">ENGINE</span>=<span class="hljs-string">&quot;InnoDB&quot;</span>
</span></code></pre>
</li>
<li><p>&#x5173;&#x4E8E;&#x8868;&#x7C7B;&#x578B;:</p>
<pre><code class="lang-sql">  MySQL&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x8868;&#x7C7B;&#x578B;&#x4E00;&#x822C;&#x5E38;&#x7528;&#x4E24;&#x79CD;&#xFF1A;MyISAM&#x548C;InnoDB

  &#x533A;&#x522B;&#xFF1A;

  MyISAM&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x6587;&#x4EF6;&#x6709;&#x4E09;&#x4E2A;frm\(&#x7ED3;&#x6784;\)&#x3001;MYD&#xFF08;&#x6570;&#x636E;&#xFF09;&#x3001;MYI&#xFF08;&#x7D22;&#x5F15;&#xFF09;

  MyISAM&#x7C7B;&#x578B;&#x4E2D;&#x7684;&#x8868;&#x6570;&#x636E;&#x589E; &#x5220; &#x6539;&#x901F;&#x5EA6;&#x5FEB;&#xFF0C;&#x4E0D;&#x652F;&#x6301;&#x4E8B;&#x52A1;&#xFF0C;&#x6CA1;&#x6709;InnoDB&#x5B89;&#x5168;&#x3002;

  InnoDB&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x6587;&#x4EF6;&#x53EA;&#x6709;&#x4E00;&#x4E2A; .frm

  InnoDB&#x7C7B;&#x578B;&#x7684;&#x8868;&#x6570;&#x636E;&#x589E; &#x5220; &#x6539;&#x901F;&#x5EA6;&#x6CA1;&#x6709;MyISAM&#x7684;&#x5FEB;&#xFF0C;&#x4F46;&#x652F;&#x6301;&#x4E8B;&#x52A1;&#xFF0C;&#x76F8;&#x5BF9;&#x5B89;&#x5168;&#x3002;
</code></pre>
</li>
<li><p>&#x5220;&#x9664;&#x8868;</p>
<pre><code class="lang-sql">  MySQL&#x4E2D;&#x5220;&#x9664;&#x6570;&#x636E;&#x8868;&#x662F;&#x975E;&#x5E38;&#x5BB9;&#x6613;&#x64CD;&#x4F5C;&#x7684;&#xFF0C; &#x4F46;&#x662F;&#x4F60;&#x518D;&#x8FDB;&#x884C;&#x5220;&#x9664;&#x8868;&#x64CD;&#x4F5C;&#x65F6;&#x8981;&#x975E;&#x5E38;&#x5C0F;&#x5FC3;&#xFF0C;&#x56E0;&#x4E3A;&#x6267;&#x884C;&#x5220;&#x9664;&#x547D;&#x4EE4;&#x540E;&#x6240;&#x6709;&#x6570;&#x636E;&#x90FD;&#x4F1A;&#x6D88;&#x5931;&#x3002;

  <span class="hljs-operator"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> table_name ;</span>
</code></pre>
</li>
</ul>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/part1/2.MySQL数据类型.html" class="navigation navigation-prev " aria-label="Previous page: MySQL数据类型"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/part1/4.DML操作：增,删,改.html" class="navigation navigation-next " aria-label="Next page: DML操作：增,删,改"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
